﻿package engine.ui
{
	import com.greensock.TweenLite;
	
	import engine.control.BaseControl;
	import engine.control.ControlCreater;
	import engine.control.ControlType;
	import engine.data.ModelLocator;
	import engine.display.guide.GuideLogic;
	import engine.logic.ActSee;
	import engine.logic.hotKey.HotKeyManage;
	import engine.logic.loading.LoadingLogic;
	import engine.logic.login.LoginLogic;
	import engine.net.event.CustomMsgEvent;
	import engine.net.messages.CustomToClientFlag;
	import engine.net.messages.CustomToServerFlag;
	import engine.net.mgr.SystemSender;
	import engine.newUi.*;
	import engine.scene.SceneChangeManager;
	import engine.ui.chat.ChatUI;
	import engine.ui.lite.BaseUI;
	
	import flash.display.DisplayObject;
	import flash.display.DisplayObjectContainer;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.utils.getDefinitionByName;
	import flash.utils.getQualifiedClassName;
	import flash.utils.getTimer;
	
	import newx.StageInfo;
	import newx.com.config.StaticIni;
	import newx.com.control.NxClip;
	import newx.com.control.text.NxLabel;
	import newx.com.control.text.NxText;
	import newx.com.control.window.NxWindowEvent;
	import newx.utils.debug.IO;

//	import newx.com.debug.DebugWindow;

	public class UIManage
	{
		private static 	var _self			:UIManage;
		//默认打开界面在最大数量 
		public static const  _uiNo			:int 		= 	4;
		
		private 			const 	_uiPrefix	:String		=	"PAUI_";
		
		private 			var _maskUI			:Sprite;
		
		private 			var _custMaskUI		:Sprite;
		
		private			var _maskEnable		:Boolean	=	true;
		
		public  			var _uiArray		:Array  	= 	[];
		
		private			var _uiTotal		:uint		=	0;
		
		/**创建完成事件函数*/
		private			var _completeFunc	:Function;
		
		private			var _createComplete	:Boolean	=	false;
		
		public 			var _creating		:int		=	0;
		
		private 			var _creatingMax	:int		=	10;
		
		private			var _uiCreateTime	:int;
		
		private 			var _uiMaxNum		:int;
		
		private 			var _uiObject		:Object;
		/***UI是否全部创建完成**/
		public 			var _uiIsCreateOver	:Boolean = false;
		
		public function UIManage()
		{
		}

		public static function getInstance():UIManage
		{
			if(_self == null)
			{
				_self = new UIManage();
			}
			return _self;
		}
		
		public function StartCreateUI(completeFunc:Function):void 
		{
			if(LoginLogic.LoginMode	==	LoginLogic.Mode_UniteLogin)
			{
//				LoadingLogic.getInstance().setProcess(0,StaticIni.getSwfLangStr("UIStr_1001387"));
			}
			
			ActSee.PostLoginStatus(8998, 1, 0);
			
			_uiCreateTime	=	getTimer();
			_completeFunc	=	completeFunc;
			StageInfo.stage.addEventListener(Event.ENTER_FRAME,FindUIToInit);
			
			_uiObject = StaticIni.getIniObj("UIRegedit");;
		}
		
		private function FindUIToInit(e:Event):void
		{
			_uiMaxNum	=	0;
			
			_creating	=	0;

			//主界面=========================================================================
			initUI(TopPlayerUI			.getInstance(),"TopPlayerUI");
			initUI(BottomIndexUI		.getInstance(),"BottomIndexUI");
			initUI(RightTopIndexUI		.getInstance(), "RightTopIndexUI");
			initUI(DepotUI			.getInstance(), "DepotUI");
			
			//任务追踪
			initUI(TaskTrackingUI			.getInstance(),"TaskTrackingUI");//6
			//对话界面
			initUI(NpcTalkUI			.getInstance(),"NpcTalkUI");//6
			//任务列表界面
			initUI(TaskListUI			.getInstance(),"TaskListUI");//28
			//聊天
			initUI(ChatUI				.getInstance(),"ChatUI");//25
			
//			initUI(FaceIconViewUI		.getInstance(),"FaceIconViewUI");
			//掉落
			initUI(ActionResultUI        .getInstance(),"ActionResultUI");
			//副本评价
			initUI(ActionEctypeResultUI  .getInstance(), "ActionEctypeResultUI");
			//副本
			initUI(DuplicatesUI  		 .getInstance(), "DuplicatesUI");
			//扫荡界面
			
			initUI(WipeOutUI 		 .getInstance(), "WipeOutUI");

			initUI(TaskTrackingUI		.getInstance(),"TaskTrackingUI");

			initUI(SitCrossleggedUI		.getInstance(),"SitCrossleggedUI");
			initUI(SitAlerUI			.getInstance(),"SitAlerUI");
			initUI(PkListUI				.getInstance(), "PkListUI");
			initUI(WorldMapLogic		.getInstance().ui,"WorldMapUI");
			
			//vip
			initUI(VipUI				.getInstence(), "VIPUI" );
			
			initUI(DetailPropertyLogic.getInstance().ui,"DetailPropertyUI");
			
			initUI(DetailsOtherPropertyLogic.getInstance().ui,"DetailPropertyUI");
			initUI(PackLogic.getInstance().ui,"PackUI");
			initUI(EmbattleLogic.getInstance().ui,"EmBattleUI");
			
			initUI(PartnerRequestLogic.getInstance().ui,"PartnerRequestUI");
			initUI(PartnerRequestNewUI.getInstance(), "PartnerRequestNewUI");

			initUI(TopOtherPlayerLogic.getInstance().ui,"TopOtherPlayerUI")
			
			initUI(FriendUI				.getInstance(), "FriendUI");
			initUI(ActivitesGroupLogic.getInstance().ui,"ActivitesGroupUI");

			initUI(MyPropertyLogic.getInstance().ui,"ActorPropertyUI");
			initUI(ActorPropertyLogic.getInstance().ui,"ActorPropertyUI");
//			/**技能界面***/
//			initUI(SkillLogic.getInstance().ui,"SkillUI");
			
			
			initUI(EquipModifiedUI.getInstance(),"EquipModifiedUI");
//			initUI(PkListUI.getInstance(),"PkListUI");
			
			initUI(IndustryLogic.getInstance().ui,"IndustryUI");
			
//			/**帮派排名界面***/
			initUI(FamilyLogic.getInstance().ui,"FamilyUI");
//			
			//帮派公告修改
			initUI(FamilyPlacardUI		.getInstance(),"FamilyPlacardUI");//7
			
			//帮派转让帮主功能
			initUI(FamilySwitchHeadLogic.getInstance().ui,"FamilySwitchHeadUI");//7
			
			//帮派转让帮主功能
			initUI(FamilyInfoUI.getInstance(),"FamilyInfoUI");//7
			
			initUI(ActivitiesUI.getInstance(),"ActivitiesUI");
//			
//			//发送邮件
			initUI(SendMailUI			.getInstance(),"SendMailUI");//23
			//商店界面
			initUI(SellUI				.getInstance(),"SellUI"); // 18
            initUI(ComposeItemUI		.getInstance(),"ComposeItemUI");
			initUI(CampBattleUI			.getInstance(),"CampBattleUI");
			initUI(CurrencyResultUI		.getInstance(),"CurrencyResultUI");
			//丹药
			initUI(IntensifyUI		.getInstance(),"IntensifyUI");
			//拜师学艺
			initUI(EmulateUI		.getInstance(),"EmulateUI");
			//
			initUI(StatusShopUI		.getInstance(),"StatusShopUI");
			
			initUI(WhisperLogic.getInstance().UI,"FaceIconViewUI");

			initUI(EmulatePartnerLogic.getInstance().ui,"EmulatePartnerUI");
			//上香
			initUI(SacredUI			.getInstance(),"SacredUI");
			
			initUI(PostRewardLogic.getInstance().ui,"PostRewardUI");
//----------------------------------------------------------
//
//			//读邮件
			initUI(SeeMailUI			.getInstance(),"SeeMailUI");//30
//			//邮件
			initUI(MailUI				.getInstance(),"MailUI"); //18

			initUI(CampChooseUI				.getInstance(),"CampChooseUI"); //18

			//经营副本
			initUI(EliteFBUI.getInstance(),"EliteFBUI");
			initUI(MysterySellUI.getInstance(),"MysterySellUI");
//			//强制提示
			initUI(AlertTimeLoseUI		.getInstance(),"AlertTimeLoseUI");//8
//			
//			//-----------------------------------------------------------------
//			
			initUI(SystemConfigureUI.				getInstance(),"SystemConfigureUI");
			initUI(BanksUI.							getInstance(),"BanksUI");
			initUI(WorldBossRankUI			.getInstance(),	"WorldBossRankUI");
		
			initUI(DailyWorkLogic.getInstance().ui, "DailyWorkUI");
			//帮派战战报界面
			initUI(FactionActionUI			.getInstance(),"FactionActionUI");
			//帮派战战场界面
			initUI(FactionAttackUI			.getInstance(),"FactionAttackUI");
			//帮派战报名查看界面
			initUI(FactionBattleLookUI		.getInstance(),"FactionBattleLookUI");
			//帮派战报名界面
			initUI(FactionBattleSignUI		.getInstance(),"FactionBattleSignUI");
			//帮派战晋级界面
			initUI(FactionWinInfroUI		.getInstance(),"FactionWinInfroUI");

			initUI(FactionBattleGiftUI		.getInstance(),	"FactionBattleGiftUI");
			//排行榜排名
			initUI(PkListRankUI.			getInstance(),	"PkListRankUI");
			
			//世界boss血条
			initUI(WorldBossBloodUI				.getInstance(),	"WorldBossBloodUI");
			//离开世界boss FB
			initUI(WorldBossExitUI				.getInstance(),	"WorldBossExitUI");
			//江湖
//			initUI(RiverLakeLogic.getInstance().ui				,"RiverLakeUI");
			
			initUI(CDClearTypeUI				.getInstance(), "CDClearTypeUI");
			
			initUI(DiceLogic.getInstance().ui,"DiceUI");
			
//			initUI(FuncPowerLogic.getInstance().ui,"FuncPowerUI");
			
			initUI(ExChangePowerLogic.getInstance().ui,"ExChangePowerUI");
			
			initUI(EscortSceneUI.getInstance(),"EscortSceneUI");
			initUI(EscortUI.getInstance(),"EscortUI");
			
			initUI(FunctionGuideUI.getInstance(),"FunctionGuideUI");
			//新手引导界面
			initUI(GuideLogic.getInstance().ui,"GuideUI");
			
			
			//游历
			initUI(TourUI.getInstance(), "TourUI" );
			//提升界面
			initUI(UpNoticeLogic.getInstance().ui,"UpNoticeUI");
			
			initUI(EveryDaySignUI.getInstance(),"EveryDaySignUI");
			
			//帮派活动——一醉方休
			initUI(FamilyDinnerUI.getInstance(), "FamilyDinnerUI");
			
			//帮派活动列表
			initUI(FamilyActiveUI.getInstance(), "FamilyActiveUI");
			
			//领取元宝
			initUI(GetMagicCoinUI.getInstance(), "GetMagicCoinUI");
			
			initUI(NextActivityGuideUI.getInstance(), "NextActivityGuideUI");
			
			initUI(QuestionUI.getInstance(),"QuestionUI");
			
			initUI(QuestionItemUI.getInstance(),"QuestionItemUI");
			
			initUI(BossTimeSetUI.getInstance(),"BossTimeSetUI");
			
			initUI(FactionBossExitUI.getInstance(),"FactionBossExitUI");
			
			initUI(FactionBossRankUI.getInstance(),"FactionBossRankUI");
			
			initUI(FactionBossUI.getInstance(),"FactionBossUI");
			
			//领取新手礼包
			initUI(ChangeUI.getInstance(),"ChangeUI");
			
			initUI(WashMarrowLogic.getInstance().ui,"WashMarrowUI");
			initUI(DoMarrowLogic.getInstance().ui,"DoMarrowUI");
			
			initUI(WlybLogic.getInstance().ui,"WlybUI");
			initUI(WlybBoxFightLogic.getInstance().ui,"WlybBoxFightUI");
			
			initUI( WlybGetLogic.getInstance().ui, "WlybGetUI" );
			
			//宠物
			initUI( PetUI.getInstance(), "PetUI" );
			
			//排行榜
			initUI(RankUI.getInstance(), "RankUI");
			initUI(DrawPictureUI.getInstance(), "DrawPictureUI");
			initUI(DrawInfoUI.getInstance(), "DrawInfoUI");
			
			initUI(ImpartPropertyLogic.getInstance().ui,"ImpartPropertyUI")
			
			//奇遇提示框
			initUI(TipsWindowUI.getInstance(),"TipsWindowUI");
			
			//奇遇
			initUI(AdventureUI.getInstance(),"AdventureUI");
			
			initUI(ForbiddenAreaUI.getInstance(),"ForbiddenAreaUI");
			//奇遇的二级界面
			initUI(AdventureTermUI.getInstance(),"AdventureTermUI");
			
			//五子棋
			initUI(GobangLogic.getInstance().ui, "GobangUI");
			
//			武学背包新
			initUI(KungfuPackLogic.getInstance().ui,"KungfuPackUI");
			
			//神秘禁地
			initUI(ForbiddenZoneUI.getInstance(),"ForbiddenZoneUI");
			
			initUI(BoxBuffUI.getInstance(),"BoxBuffUI");
			
			initUI(FamilyInviteUI.getInstance(),"FamilyInviteUI");
			
			initUI(WhisperLogic.getInstance().whisperUi,"WhisperUI");
			//GMCC
			initUI(GmccLogic.getInstance().gmccUi,"WhisperUI");
			//GMCC评价
			initUI(GmccOpinionUI.getInstance(),"GmccOpinionUI");
			//GMCC功能界面
			initUI(GmccFunctionUI.getInstance(),"GmccFunctionUI");
			//活动面板
			initUI(ActionFaceplateUI.getIntence(),"ActionFaceplateUI");
			
			initUI(WarfareUI.getInstance(),"WarfareUI");
			//精彩活动
			initUI(ActionFaceplateUI.getIntence(), "ActionFaceplateUI");
			
			//查询帮派所有成员界面
			initUI(FamilyBodyLogic.getInstance().ui,"FamilyBodyUI");
			
			//帮派商人
			initUI(FamilyShopUI.getInstance(), "FamilyShopUI");
			//战斗力提升面板 
//			initUI(FightUpUI.getInstance(), "FightUpUI");
			//宝物商人
			initUI(TreasureShopUI.getInstance(), "TreasureShopUI");
			//聚宝盆
			initUI(TreasureBowlMainUI.getInstance(), "TreasureBowlMainUI");
//			initUI(UpSkillHelpUI.getInstance(), "UpSkillHelpUI")
//
//			initUI(CDClearTypeUI.getInstance(),"CDClearTypeUI");
//			
//			//CD消耗提示
//			initUI(BattleFBTimeUI.getInstance(),"BattleFBTimeUI");
		
			//家族===========================================================================
			
			//所有家族浏览
//			initUI(FamilyBrowseUI		.getInstance(),"FamilyBrowseUI");

			//幸运大转盘界面
			initUI(LuckyWheelLogic.getInstance().ui,"LuckyWheelUI");
			//幸运大转盘奖品提示框
			initUI(LuckyPrizeListLogic.getInstance().ui,"LuckyPrizeListUI");
			//龙女出谷
			initUI(DragonGoPlayUI.getInstance(),"DragonGoPlayUI");
			//手机验证
			initUI(MobileCheckUI.getInstance(),"MobileCheckUI");

			//s首次充值大禮包
			initUI(ChongZhiDaLiBaoLogic.getInstance().ui,"ChongZhiDaLiBaoUI");
			//春节集字活动
			initUI(ExchangeWordLogic.getInstance().ui,"ExchangeWordUI");
			//春节猜谜活动
			initUI(GuessWordLogic.getInstance().ui,"GuessWordUI");
			//活动商城
//			initUI(TreaShoppingUI.getInstance(),"TreaShoppingUI");
			//春节红包
			initUI(ChristmastimeUI.getInstance(),"ChristmastimeUI");
			//经脉
			initUI(PulseLogic.getInstance().ui,"PulseUI");
			
			initUI(SpecialKungFuUI.getInstance(),"SpecialKungFuUI");
			
			initUI(SpecialKungfuInfoUI.getInstance(),"SpecialKungfuInfoUI");
			
			//公告
			initUI(NoticerUI.getInstance(),"NoticerUI");
			
			initUI(MakeSnowUI.getInstance(),"MakeSnowUI");
			initUI(SnowBossBloodUI.getInstance(),"SnowBossBloodUI");
			initUI(SnowBossExitUI.getInstance(),"SnowBossExitUI");
			initUI(SnowBossRankUI.getInstance(),"SnowBossRankUI");
			
			if(LoginLogic.LoginMode	==	LoginLogic.Mode_UniteLogin)
			{
//				LoadingLogic.getInstance().setProcess(100 * _uiTotal/_uiMaxNum,StaticIni.getSwfLangStr("UIStr_1001387"));
			}
			
			if(_creating == 0)
			{
				initUiMask();
				
				invoke();
				
				_createComplete	=	true;
				
				_uiCreateTime	=	getTimer() - _uiCreateTime;
				
				IO.traceLog("创建界面总个数：",_uiTotal,"总时间:",_uiCreateTime,"平均创建时间：",_uiCreateTime/_uiTotal);
			}
			
			if(_createComplete)
			{
				StageInfo.stage.removeEventListener(Event.ENTER_FRAME,FindUIToInit);
				IO.traceLog("UICreateComplete");
				if(LoginLogic.LoginMode	==	LoginLogic.Mode_UniteLogin)
				{
//					LoadingLogic.getInstance().setProcess(100,StaticIni.getSwfLangStr("UIStr_1001387"));
				}
				_completeFunc.call(this);
				_uiIsCreateOver = true;
			}
		}
		
		private function invoke():void
		{																		

			ModelLocator.getInstance().addEventListener(String(CustomToClientFlag.SERVER_CUSTOMMSG_OPEN_UI),openUI);
			ModelLocator.getInstance().addEventListener(String(CustomToClientFlag.SERVER_CUSTOMMSG_CLOSE_UI),closeUI);		
			
		}
		
		//============================UI 面板 开关 Start===============================================
		
		private function openUI(e:CustomMsgEvent):void
		{
			var data:Array=e.pList;
			var uiid:int=data[0];//用来打开面板
//			/**神秘商店界面**/
			MysterySellLogic.getInstance().SellType= int(data[1]) ; 
			
			var ui:BaseUI=this.getUI(uiid);
			var posObj:Object=StaticIni.getIniObj(_uiPrefix+uiid);
			
			if(ui)
			{
				ui.show(StageInfo.uiSpace);
				
				if(posObj)
				{
					ui.x=posObj.x;
					ui.y=posObj.y;
				}
			}
		}
		
		private function closeUI(e:CustomMsgEvent):void
		{
			var data:Array=e.pList;
			
			var uiid:int=data[0];
			
			var ui:BaseUI=UIManage.getInstance().getUI(uiid);
			
			if(ui)
			{
				ui.hide();
			}
		}
		
		//============================UI 面板 开关 END===============================================
		
		public function setUIMask(view:DisplayObjectContainer):void
		{
			if(_maskEnable == true)
			{
				cancelUIMask()
				view.addChild(_maskUI);
				_maskUI.x = SceneChangeManager.getGameX();
				_maskUI.y = SceneChangeManager.getGameY();
			}
		}
		
		public function setCustUIMask(view:DisplayObjectContainer,alpha:Number=0,tween:Boolean=false,pierceAble:Boolean=false):void
		{
			if(_maskEnable == true)
			{
				_custMaskUI.mouseChildren = _custMaskUI.mouseEnabled = !pierceAble;
				
				if(tween)
				{
					_custMaskUI.alpha = 0;
					cancelCustUIMask()
					view.addChild(_custMaskUI);
					_custMaskUI.x =  SceneChangeManager.getGameX();
					_custMaskUI.y =  SceneChangeManager.getGameY();
					//关闭快捷键
					HotKeyManage.getInstance().enabled = false;
					
					TweenLite.to(_custMaskUI,0.5,{alpha:alpha,onComplete:function():void
					{
						_custMaskUI.alpha = alpha;
						
					}});
				}
				else
				{
					_custMaskUI.alpha = alpha;
					cancelCustUIMask()
					view.addChild(_custMaskUI);
					_custMaskUI.x =  SceneChangeManager.getGameX();
					_custMaskUI.y =  SceneChangeManager.getGameY();
					//关闭快捷键
					HotKeyManage.getInstance().enabled = false;
				}
			}
		}
		
		
		public function get maskEnable():Boolean
		{
			return _maskEnable;
		}
		
		public function set maskEnable(value:Boolean):void
		{
			_maskEnable = value;
			if(_maskEnable	==	false)
			{
				cancelCustUIMask();
				cancelUIMask()
			}
		}
		
		public function cancelCustUIMask(tween:Boolean=false):void
		{
//			_custMaskUI.visible = false;
			if(tween)
			{
				TweenLite.to(_custMaskUI,0.4,{alpha:0,onComplete:function():void
				{
					if(	_custMaskUI	!=	null	&&	_custMaskUI.parent != null){
						_custMaskUI.parent.removeChild(_custMaskUI);
						//开启快捷键
						HotKeyManage.getInstance().enabled = true;
					}
				}});
			}
			else
			{
				if(	_custMaskUI	!=	null	&&	_custMaskUI.parent != null){
					_custMaskUI.parent.removeChild(_custMaskUI);
					//开启快捷键
					HotKeyManage.getInstance().enabled = true;
				}
			}
		}
		
		public function cancelUIMask():void
		{
			if(_maskUI!=null &&_maskUI.parent != null)
				_maskUI.parent.removeChild(_maskUI);
		}
		
		/**
		 * 弹出UI 
		 * @param id
		 */		
		private function showUI(id:int):void
		{
			var className	:String	=	_uiObject["UI_"+id];
			if(className)
			{
				var UIClass		:Class	=flash.utils.getDefinitionByName("engine.engine.newUi." +  className) as Class;
				
				var ui			:BaseUI	=	UIClass.getInstance() as BaseUI;
				
				ui.show();
			}
			else
			{
				IO.traceLog("找不到id号对应的UI界面,id:"+id);
			}
		}
		
		/**
		 *获取UI 
		 * @return 
		 */		
		public function getUI(id:int):BaseUI
		{
			var className	:String	=	_uiObject["UI_"+id];
			var roleLogic	:String =   _uiObject["UI_"+id];
			if(id == 1)
			{
				className = className.replace("MyProperty","ActorProperty");
			}
			if(id == 89)
			{
				className = className.replace("DetailsOtherProperty","DetailProperty");
			}
			var ui			:BaseUI;
			if(className)
			{
				try
				{
					var UIClass		:Class	=flash.utils.getDefinitionByName("engine.newUi." + className) as Class;
					
					if( UIClass.hasOwnProperty( "getInstance" ) )
					{
						ui	=	UIClass.getInstance() as BaseUI;
					}else
					{
						
						if(id == 1 || id == 89)
						{
							UIClass	=flash.utils.getDefinitionByName("engine.newUi." + roleLogic.replace("UI","Logic")) as Class;
						}else
						{
							UIClass	=flash.utils.getDefinitionByName("engine.newUi." + className.replace("UI","Logic")) as Class;
						}
						ui	=	UIClass.getInstance()["ui"] as BaseUI;
					}
					
				}
				catch(e:*)
				{
					
				}
			}
			
			return ui;

		}
		
		public function getUIid(ui:BaseUI):int
		{
			var totalName:String=flash.utils.getQualifiedClassName(ui);
			
			var uiName:String=totalName.split("::")[1];
			var uiid:int;
			
			var proName:String;
			
			for	(	proName	in _uiObject	)
			{
				if(_uiObject[proName]	==	uiName	)	
				{
					uiid=proName.split("_")[1];
					break;
				}
			}
			
			return	uiid;
		}
		
		public function requestOpenUI(ui:BaseUI):void
		{
			var uiid:int	=	UIManage.getInstance().getUIid(ui);
			
			SystemSender.getInstance().CustomMsg(CustomToServerFlag.CLIENT_CUSTOMMSG_REQUEST_OPEN_UI,uiid);
		}
		
		public function requestHideUI(ui:BaseUI):void
		{
			var uiid:int	=	UIManage.getInstance().getUIid(ui);
			
			SystemSender.getInstance().CustomMsg(CustomToServerFlag.CLIENT_CUSTOMMSG_REQUEST_CLOSE_UI,uiid);
			
			IO.traceLog("UI请求关闭	："	+	uiid	);
		}
		
		private function initUiMask():void
		{
			//初始化蒙版
			_maskUI = new Sprite();
			_maskUI.graphics.beginFill(0x333333,1);
			_maskUI.graphics.drawRect(0,0,StageInfo.rootMaxW,StageInfo.rootMaxH);
			_maskUI.graphics.endFill();
			_maskUI.alpha	=	0;
			
			_custMaskUI	= new Sprite();			
			_custMaskUI.graphics.beginFill(0x000000,1);
			_custMaskUI.graphics.drawRect(0,0,StageInfo.rootMaxW,StageInfo.rootMaxH);
			_custMaskUI.graphics.endFill();
			_custMaskUI.alpha	=	0;
		}
		
		private function getArrayByStr(val:String):*
		{
			var pattern:RegExp = /^[$].*[$]$/;
			
			if(val.match(pattern))
			{
				if(val.length > 2)
				{
					var	strSub:String	=	val.substr(1, val.length - 2);
					return	strSub.split(";");	
				}
				else
				{
					return	new Array();
				}
			}
			return null;		
		}
		
		
		private function getLangStr(val:String):String
		{
			var pattern:RegExp = /^[##].+[##]$/;
			
			if(	val.match(pattern))
			{						
				var strSub:String	=	val.substr(2, val.length - 4);
				return StaticIni.getSwfLangStr(strSub);							
			}
			return val;
		}
		
		private function checkArrLang(arr:Array):Array
		{
			if(arr == null || arr.length == 0)
			{
				return null;
			}
			var tSize:uint	=	arr.length;
			for(var i:uint = 0 ; i < tSize ; i++)
			{
				arr[i]	=	getLangStr(arr[i])
			}
			return arr;
		}
		private function CreateUIControl(controls:Array,ui:BaseUI,className:String):void
		{
			if(className=="EmbattleUI")
				trace("UIManage.CreateUIControl(controls, ui, className)",controls);
			
//			var ui:BaseUI	=	StaticIni.getClipClass(StageInfo.stage.loaderInfo,"engine.ui."+className).getInstance();
					
			var parentSpace		:DisplayObjectContainer;
					
			var tSize			:uint	=	controls.length;
			
			//组件变量
			var controlsVar		:String;
			//组件类型
			var controlType		:String;
			//组件参数
			var controlSet		:Array;
			
			//父对象
			var controlParent	:Object;
			
			var creatObj		:Object;
						
			for(var i:uint = 0 ; i < tSize ; i ++)
			{
				controlsVar	=	controls[i];
				
				creatObj	=	StaticIni.getIniObj(className+"_"+controlsVar);
				
				controlSet	=	creatObj["create"].split(",");
				
				controlType	=	controlSet.shift();
				
				for	(var iSet:int	=	0;	iSet < controlSet.length; iSet++)
				{
					var	 strArr:String	=	controlSet[iSet];
					
					var	 obj:*			=	getArrayByStr(strArr);
					if( null == obj)
					{
//						controlSet[iSet] = strArr;
						
						if(controlSet[iSet] is Boolean)
						{
							controlSet[iSet]	=	Boolean(strArr);
						}
						else if(controlSet[iSet] is String)
						{
							controlSet[iSet]	= getLangStr(strArr);
						}
						else if(controlSet[iSet] is int)
						{
							controlSet[iSet]	= int(strArr)
						}
						else if(controlSet[iSet] is Number)
						{
							controlSet[iSet]	= Number(strArr);
						}
					}
					else
					{
						if(obj is Array)
						{
							controlSet[iSet] = checkArrLang(obj);
						}
						else
						{
							controlSet[iSet] = getLangStr(strArr);
						}	
					}
				}
				
				ControlCreater.getInstance().CreateControl(controlType,controlSet,ui,controlsVar);
				
				controlParent			=	creatObj["parent"];
				
				if(null != controlParent && controlParent != "")
				{
					if(controlParent == "this")
					{
						//当配置成“this”时，显示对象为界面类本身
						parentSpace	=	ui	as DisplayObjectContainer;
					}
					else
					{
						if(ui[controlParent] is BaseControl)
						{
							//BaseControl 的子类，显示容器为.content
							parentSpace	=	ui[controlParent].content	as DisplayObjectContainer;
						}
						else
						{
							//非继承BaseControl的控件，显示对象就是其本身
							parentSpace	=	ui[controlParent]	as DisplayObjectContainer;
						}						
					}
					
					switch(controlType)
					{
						//ButtonList属于特殊控件，不需要添加到舞台
						case ControlType.ButtonList:
							break;
						//非继承BaseControl的控件直接调用addChild方便进行显示对象的添加
						case ControlType.NxClip:
						case ControlType.NxInput:
						case ControlType.CustomControl:
						case ControlType.NxComboBox:
						case ControlType.Sprite:
						case ControlType.NxTab:
						case ControlType.NxTable:
						case ControlType.NxButton:
						case ControlType.NxList:
							parentSpace.addChild(ui[controlsVar]);
							break
						default:
						//其余继承BaseControl调用show方法创建
							ui[controlsVar].show(parentSpace);
							break;	
					}
				}
				var	contentArr:Object	=	StaticIni.getIniObj(className+"_"+controlsVar);
					
//				trace("循环p in con")
				
				/**属性数组*/
				var pStrArr:Array	=	new Array();
				for(var pro:String in contentArr)
				{
					pStrArr.push(pro);
				}
				
				var tpSize:int	=	pStrArr.length;
				
				var p:String;
				
				for(var j:int = 0 ; j< tpSize ; j ++)
				{
					p	=	pStrArr[j];
					if("parent" != p && "create" != p)
					{
						strArr	=	contentArr[p];
						
						obj		=	getArrayByStr(strArr);
						
						if(obj != null)
						{
							if(obj is Array)
							{
								contentArr[p] = checkArrLang(obj);
							}
							else
							{
								contentArr[p] = getLangStr(strArr);
							}
						}
						
						if(ui[controlsVar][p] is Boolean)
						{
							if(contentArr[p] == "true" || contentArr[p] == "1")
							{
								ui[controlsVar][p]	=	true;
							}
							else
							{
								ui[controlsVar][p]	=	false;
							}
						}
						else if(ui[controlsVar][p] is String)
						{
							ui[controlsVar][p]	= getLangStr(contentArr[p]);
						}
						else if(ui[controlsVar][p] is int)
						{
							if((ui[controlsVar] is NxText || ui[controlsVar] is NxLabel) && p == "color")
							{
								ui[controlsVar][p]	= uint("0x" + contentArr[p]);
							}else
							{
								ui[controlsVar][p]	= int(contentArr[p])
							}
						}
						else if(ui[controlsVar][p] is Number)
						{
							ui[controlsVar][p]	= Number(contentArr[p]);
						}
						
//						if(	"EquipUpgradeUI"	==	className	&& ui[controlsVar] is NxTable)
//						{
//							trace("P:",p,"--",contentArr[p],"---",ui[controlsVar][p]);
//						}
					}
				}
			}
			if(ui.windowBG)
			{
				var jpg:String=StaticIni.getIniVar("UIwithPictrueHelp",className);
				if(!jpg)return 
				jpg="res/jpg/"+jpg;
				ui.windowBG.helpBtnVisible=true;
				ui.windowBG.addEventListener(NxWindowEvent.WINDOW_HELP,function(e:Event):void{
					var bG:NxClip=new NxClip;
					bG.buttonMode=true;
					StageInfo.systemSpace.addChild(bG);
					bG.addEventListener(MouseEvent.CLICK,function (e:Event):void{
						bG.clear();
						bG.parent.removeChild(bG);
					}
					)
					bG.addLoadedEvent(function(val:DisplayObject):void{
						bG.x	=	 (SceneChangeManager.getGameWidth() - val.width  + SceneChangeManager.getGameX())/3;
						bG.y	=	(SceneChangeManager.getGameHeight()/2-val.height)/2
					},Event.COMPLETE)
					bG.source=jpg;
				})
			}
		}
		public function initUI(ui:BaseUI,className:String):void
		{
//			try
//			{
	//			trace("_creatingLines",_creatingLines)
				_uiMaxNum++;
				if(_creating < _creatingMax && !ui.inited)
				{
	//				if(DebugWindow.enabled)
	//				{
					var checkTime:int	=	getTimer();
	//				}
					
					_creating++;
					_uiTotal ++;
					
					var	arrObj:Object	=	StaticIni.getIniObj(className);
					for(var p:String in arrObj)
					{
						if("controls"	==	p)
						{
							var controls:Array	=	arrObj[p].split(",");
							CreateUIControl(controls,ui,className);
						}
						else
						{
							ui[p]	=	arrObj[p];
						}
					}
					ui.Init();
					ui.mouseChildren 	= 	ui.mouseEnabled = ui.visible = false;
					ui.inited			=	true;
					
	//				if(DebugWindow.enabled)
	//				{
					checkTime	=	getTimer()	-	checkTime;
					IO.traceLog("InitUI:\t",className+"\tTime：\t"+checkTime);
	//				}
				}
//			}
//			catch(e:Error)
//			{
//				IO.traceError("创建界面失败！" ,ui,className);
//				trace("创建界面失败！" ,ui,className);
//				ui.inited 				=	true;
//			}
		}	
		
		
		/**
		 *关闭不相关的UI
		 * 
		 */
		public function hideOtherOpendUI(showArr:Array = null,id:int = 0):void
		{
			if(TipsWindowUI.getInstance().created==true)
			{
				return ; 
			}
			var allShowList:Array = StaticIni.getIniVar("allShowType","allShowList").split(",");
			var showDownList:Array =  StaticIni.getIniVar("allShowType","SUI_" + id).split(",");
			for(var i:int = 0;i<_uiArray.length;i++)
			{
				var curUI:BaseUI = _uiArray[i] as BaseUI;
				var uiid:int = UIManage.getInstance().getUIid(curUI);
				
				if(curUI is ActorPropertyUI && (curUI as ActorPropertyUI).logicControl is MyPropertyLogic)
				{
					uiid = 1;
				}
				if(curUI is DetailPropertyUI && ((curUI as DetailPropertyUI).logicControl as DetailPropertyLogic).isOther)
				{
					uiid = 89;
				}
				if(id == uiid)continue;
				if(allShowList.indexOf("UI_"+uiid) != -1)
				{
					continue;
				}
				if (curUI == null)
				{
					return;
				}
				if(null == showArr && allShowList.indexOf("UI_"+uiid) == -1 && showDownList.indexOf("UI_" + uiid) == -1)
				{
					curUI.hideCur();
					i--;
				}else if(showArr!=null&& showArr.indexOf("UI_"+ uiid) == -1 && showDownList.indexOf("UI_" + uiid) == -1 )
				{
					curUI.hideCur();
					i--;
				}else
				{
					
				}
			}
		}
		
		/**
		 * 隐藏所有已打开的UI界面
		 * 
		 */		
		public function hideOpenedUI(showArr:Array = null,id:int = 0):void
		{	
			
			while (_uiArray.length > 0)
			{
				var curUI:BaseUI = _uiArray[0] as BaseUI;
				var uiid:int = UIManage.getInstance().getUIid(curUI);
//				trace(uiid);
				if (curUI == null || uiid == 95 || uiid == 94)//界面为  提升界面时不关闭
				{
					_uiArray.shift();
					continue;
				}
				if(null == showArr)
				{
					curUI.hide();
				}else if( showArr.indexOf("UI_"+uiid)==-1)
				{
					curUI.hide();
				}
			}
			cancelCustUIMask();
			cancelUIMask();
			
		}
		
		/**
		 *禁止所有UI移动 
		 * 
		 */		
		public function forbidDragUi():void
		{
			var uiid:uint;
			var ui:BaseUI;
			
			for(uiid=1;	uiid<=200	;	uiid++)
			{
				ui=getUI(uiid);
				if(	null	!=	ui)
					ui.forbidDrag();
			}
			
		}
		
		public function restoreDragUi():void
		{
			var uiid:uint;
			var ui:BaseUI;
			
			
			for(uiid=1;	uiid<=200	;	uiid++)
			{
				ui=getUI(uiid);
				if(	null	!=	ui)
					ui.restoreDrag();
			}
		}
		/**舞台缩放时调整已打开界面的位置*/
		public function onStageReSize():void
		{
			var len:uint	=	_uiArray.length;
			for(var i:uint=0;	i<len;	i++)
			{
				var curUI:BaseUI = _uiArray[i] as BaseUI;
				
				curUI.modifyPostion();
			}
			
			_custMaskUI.x = SceneChangeManager.getGameX();
			_custMaskUI.y = SceneChangeManager.getGameY();
		}
	}
}
